package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.LogisticsOrder;
import com.example.demo.entity.PurchaseOrder;
import com.example.demo.service.LogisticsOrderService;
import com.example.demo.mapper.LogisticsOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 18364
* @description 针对表【logistics_order】的数据库操作Service实现
* @createDate 2025-01-08 15:31:40
*/
@Service
public class LogisticsOrderServiceImpl extends ServiceImpl<LogisticsOrderMapper, LogisticsOrder>
    implements LogisticsOrderService{
    @Autowired
    LogisticsOrderMapper logisticsOrderMapper;

    @Override
    public LogisticsOrder selectByInfo(String userId, String trainingId, String logisticsNumber, String identifyCode,String orderNumber) {
        QueryWrapper<LogisticsOrder> queryWrapper=new QueryWrapper<>();
        if(userId!=null){
            queryWrapper.eq("userId",userId);
        }
        if(trainingId!=null){
            queryWrapper.eq("trainingId",trainingId);
        }

        if(identifyCode!=null){
            queryWrapper.eq("identifyCode",identifyCode);
        }
        if(logisticsNumber!=null){
            queryWrapper.eq("logisticsNumber",logisticsNumber);
        }
        if(orderNumber!=null){
            queryWrapper.eq("orderNumber",orderNumber);
        }
        queryWrapper.orderByDesc("shipperTime");
        List<LogisticsOrder> resultList = logisticsOrderMapper.selectList(queryWrapper);
        if (!resultList.isEmpty()) {
            return resultList.get(0); // 这里返回结果列表的第一条记录
        } else {
            return null;
        }
    }

    @Override
    public Integer delete(String userId, String trainingId, String orderNumber) {
        QueryWrapper<LogisticsOrder> queryWrapper=new QueryWrapper<>();
        if(userId!=null){
            queryWrapper.eq("userId",userId);
        }
        if(trainingId!=null){
            queryWrapper.eq("trainingId",trainingId);
        }

        if(orderNumber!=null){
            queryWrapper.eq("orderNumber",orderNumber);
        }
        return logisticsOrderMapper.delete(queryWrapper);
    }
}




